//类型别名
type xxx = number|string|boolean
let a: xxx;
a = "123";
a = 123;

function getID(id: xxx){
    //narrow 在ts中每当使用数据类型判断的时候 ts会自动的缩小 范围
    if(typeof id === "string"){
        //ts帮助确定id一定是string类型
        console.log(id.toUpperCase())
    }else {
        console.log(id)
    }
}
getID("abc")
getID(123)
getID(true)


//对象类型别名
type Data = {
    name: string,
    age: number,
    flag?: boolean
}
function sentData(data: Data){
    console.log(data.name)
    console.log(data.age)
    console.log(data.flag)
}

let data: Data = {name:"1", age:2, flag:true};

sentData(data)
sentData({name:"1",age:2})

//有规律的对象类型别名
type Obj = {
    [name:string]: string
}
let obj:Obj = {
    "a":"aa",
    "a2":"aaa",
    "a3":"aaaa",
    "a4":"aaaaa",
}
